//
//  GQHRouteModel.m
//  Xanthium
//
//  Created by GuanQinghao on 09/04/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHRouteModel.h"


@implementation GQHRouteModel

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
    
    return @{
             @"qh_routeID" : @"id",
             @"qh_userID" : @"focusUser",
             @"qh_departureID" : @"originId",
             @"qh_departure" : @"origin",
             @"qh_destinationID" : @"destinationId",
             @"qh_destination" : @"destination",
             @"qh_number" : @"num"
             };
}

/// 获取路线空车
+ (void)qh_fetchRoutesTrucksWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHRouteModel *> *routes))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buFocusOnLine/1/EmptyCarNumlist"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            NSMutableArray *routeArray = [NSMutableArray array];
            for (NSDictionary *object in [data objectForKey:@"list"]) {
                
                GQHRouteModel *routeModel = [GQHRouteModel yy_modelWithDictionary:object];
                if (routeModel) {
                    
                    [routeArray addObject:routeModel];
                }
            }
            success(YES,code,message,routeArray);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

/// 获取路线货源
+ (void)qh_fetchRoutesFreightsWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHRouteModel *> *routes))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buFocusOnLine/1/Numlist"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            NSMutableArray *routeArray = [NSMutableArray array];
            for (NSDictionary *object in [data objectForKey:@"list"]) {
                
                GQHRouteModel *routeModel = [GQHRouteModel yy_modelWithDictionary:object];
                if (routeModel) {
                    
                    [routeArray addObject:routeModel];
                }
            }
            success(YES,code,message,routeArray);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

@end
